<?php

namespace app\admin\model;
use think\Model;
use think\Db;

class ArticleModel extends Model
{
    protected $name = 'article';
    
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = true;

    //*********************************************新闻中心1*********************************************//
    /**
     * 根据搜索条件获取用户列表信息
     */
    public function getPatentByWhere($map, $Nowpage, $limits)
    {
        return $this->field('think_article.*,cate_id')->where('cate_id','=',1)->page($Nowpage, $limits)->order('id desc')->select();

    }

    /**
     * [insertArticle 添加文章]
     *
     */
    public function insertPatent($param)
    {
        try{
            $result = $this->allowField(true)->save($param);
            if(false === $result){             
                return ['code' => -1, 'data' => '', 'msg' => $this->getError()];
            }else{
                return ['code' => 1, 'data' => '', 'msg' => '文章添加成功'];
            }
        }catch( PDOException $e){
            return ['code' => -2, 'data' => '', 'msg' => $e->getMessage()];
        }
    }



    /**
     * [updateArticle 编辑文章]
     * @author [田建龙] [864491238@qq.com]
     */
    public function updatePatent($param)
    {
        try{
            $result = $this->allowField(true)->save($param, ['id' => $param['id']]);
            if(false === $result){          
                return ['code' => 0, 'data' => '', 'msg' => $this->getError()];
            }else{
                return ['code' => 1, 'data' => '', 'msg' => '文章编辑成功'];
            }
        }catch( PDOException $e){
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }



    /**
     * [getOneArticle 根据文章id获取一条信息]
     *
     */
    public function getOnePatent($id)
    {
        return $this->where('id', $id)->find();
    }



    /**
     * [delArticle 删除文章]
     *
     */
    public function delPatent($id)
    {
        try{
            $this->where('id', $id)->delete();
            return ['code' => 1, 'data' => '', 'msg' => '文章删除成功'];
        }catch( PDOException $e){
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
    //*********************************************新闻中心2*********************************************//

    /**
     * 根据搜索条件获取用户列表信息
     */
    public function getAgentByWhere($map, $Nowpage, $limits)
    {
        return $this->field('think_article.*,cate_id')->where('cate_id','=',2)->page($Nowpage, $limits)->order('id desc')->select();
    }

    /**
     * [insertArticle 添加文章]
     */
    public function insertAgent($param)
    {
        try{
            $result = $this->allowField(true)->save($param);
            if(false === $result){
                return ['code' => -1, 'data' => '', 'msg' => $this->getError()];
            }else{
                return ['code' => 1, 'data' => '', 'msg' => '文章添加成功'];
            }
        }catch( PDOException $e){
            return ['code' => -2, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
    /**
     * [updateArticle 编辑文章]
     */
    public function updateAgent($param)
    {
        try{
            $result = $this->allowField(true)->save($param, ['id' => $param['id']]);
            if(false === $result){
                return ['code' => 0, 'data' => '', 'msg' => $this->getError()];
            }else{
                return ['code' => 1, 'data' => '', 'msg' => '文章编辑成功'];
            }
        }catch( PDOException $e){
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
    /**
     * [getOneArticle 根据文章id获取一条信息]
     */
    public function getOneAgent($id)
    {
        return $this->where('id', $id)->find();
    }
    /**
     * [delArticle 删除文章]
     */
    public function delAgent($id)
    {
        try{
            $this->where('id', $id)->delete();
            return ['code' => 1, 'data' => '', 'msg' => '文章删除成功'];
        }catch( PDOException $e){
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
    //*********************************************新闻中心3*********************************************//

    /**
     * 根据搜索条件获取用户列表信息
     */
    public function getRegisterByWhere($map, $Nowpage, $limits)
    {
        return $this->field('think_article.*,cate_id')->where('cate_id','=',4)->page($Nowpage, $limits)->order('id desc')->select();
    }

    /**
     * [insertArticle 添加文章]
     */
    public function insertRegister($param)
    {
        try{
            $result = $this->allowField(true)->save($param);
            if(false === $result){
                return ['code' => -1, 'data' => '', 'msg' => $this->getError()];
            }else{
                return ['code' => 1, 'data' => '', 'msg' => '文章添加成功'];
            }
        }catch( PDOException $e){
            return ['code' => -2, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
    /**
     * [updateArticle 编辑文章]
     */
    public function updateRegister($param)
    {
        try{
            $result = $this->allowField(true)->save($param, ['id' => $param['id']]);
            if(false === $result){
                return ['code' => 0, 'data' => '', 'msg' => $this->getError()];
            }else{
                return ['code' => 1, 'data' => '', 'msg' => '文章编辑成功'];
            }
        }catch( PDOException $e){
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
    /**
     * [getOneArticle 根据文章id获取一条信息]
     */
    public function getOneRegister($id)
    {
        return $this->where('id', $id)->find();
    }
    /**
     * [delArticle 删除文章]
     */
    public function delRegister($id)
    {
        try{
            $this->where('id', $id)->delete();
            return ['code' => 1, 'data' => '', 'msg' => '文章删除成功'];
        }catch( PDOException $e){
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }

    //*********************************************新闻中心4*********************************************//

    /**
     * 根据搜索条件获取用户列表信息
     */
    public function getNewsByWhere($map, $Nowpage, $limits)
    {
        return $this->field('think_article.*,cate_id')->where('cate_id','=',3)->page($Nowpage, $limits)->order('id desc')->select();
    }

    /**
     * [insertArticle 添加文章]
     */
    public function insertNews($param)
    {
        try{
            $result = $this->allowField(true)->save($param);
            if(false === $result){
                return ['code' => -1, 'data' => '', 'msg' => $this->getError()];
            }else{
                return ['code' => 1, 'data' => '', 'msg' => '文章添加成功'];
            }
        }catch( PDOException $e){
            return ['code' => -2, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
    /**
     * [updateArticle 编辑文章]
     */
    public function updateNews($param)
    {
        try{
            $result = $this->allowField(true)->save($param, ['id' => $param['id']]);
            if(false === $result){
                return ['code' => 0, 'data' => '', 'msg' => $this->getError()];
            }else{
                return ['code' => 1, 'data' => '', 'msg' => '文章编辑成功'];
            }
        }catch( PDOException $e){
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
    /**
     * [getOneArticle 根据文章id获取一条信息]
     */
    public function getOneNews($id)
    {
        return $this->where('id', $id)->find();
    }
    /**
     * [delArticle 删除文章]
     */
    public function delNews($id)
    {
        try{
            $this->where('id', $id)->delete();
            return ['code' => 1, 'data' => '', 'msg' => '文章删除成功'];
        }catch( PDOException $e){
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
    //*********************************************通知公告*********************************************//

    /**
     * 根据搜索条件获取用户列表信息
     */
    public function getLawsByWhere($map, $Nowpage, $limits)
    {
        return $this->field('think_article.*,cate_id')->where('cate_id','=',5)->page($Nowpage, $limits)->order('id desc')->select();
    }

    /**
     * [insertArticle 添加文章]
     */
    public function insertLaws($param)
    {
        try{
            $result = $this->allowField(true)->save($param);
            if(false === $result){
                return ['code' => -1, 'data' => '', 'msg' => $this->getError()];
            }else{
                return ['code' => 1, 'data' => '', 'msg' => '文章添加成功'];
            }
        }catch( PDOException $e){
            return ['code' => -2, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
    /**
     * [updateArticle 编辑文章]
     */
    public function updateLaws($param)
    {
        try{
            $result = $this->allowField(true)->save($param, ['id' => $param['id']]);
            if(false === $result){
                return ['code' => 0, 'data' => '', 'msg' => $this->getError()];
            }else{
                return ['code' => 1, 'data' => '', 'msg' => '文章编辑成功'];
            }
        }catch( PDOException $e){
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
    /**
     * [getOneArticle 根据文章id获取一条信息]
     */
    public function getOneLaws($id)
    {
        return $this->where('id', $id)->find();
    }
    /**
     * [delArticle 删除文章]
     */
    public function delLaws($id)
    {
        try{
            $this->where('id', $id)->delete();
            return ['code' => 1, 'data' => '', 'msg' => '文章删除成功'];
        }catch( PDOException $e){
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
    //*********************************************公路要事*********************************************//

    /**
     * 根据搜索条件获取用户列表信息
     */
    public function getProblemByWhere($map, $Nowpage, $limits)
    {
        return $this->field('think_article.*,cate_id')->where('cate_id','=',6)->page($Nowpage, $limits)->order('id desc')->select();
    }

    /**
     * [insertArticle 添加文章]
     */
    public function insertProblem($param)
    {
        try{
            $result = $this->allowField(true)->save($param);
            if(false === $result){
                return ['code' => -1, 'data' => '', 'msg' => $this->getError()];
            }else{
                return ['code' => 1, 'data' => '', 'msg' => '文章添加成功'];
            }
        }catch( PDOException $e){
            return ['code' => -2, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
    /**
     * [updateArticle 编辑文章]
     */
    public function updateProblem($param)
    {
        try{
            $result = $this->allowField(true)->save($param, ['id' => $param['id']]);
            if(false === $result){
                return ['code' => 0, 'data' => '', 'msg' => $this->getError()];
            }else{
                return ['code' => 1, 'data' => '', 'msg' => '文章编辑成功'];
            }
        }catch( PDOException $e){
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
    /**
     * [getOneArticle 根据文章id获取一条信息]
     */
    public function getOneProblem($id)
    {
        return $this->where('id', $id)->find();
    }
    /**
     * [delArticle 删除文章]
     */
    public function delProblem($id)
    {
        try{
            $this->where('id', $id)->delete();
            return ['code' => 1, 'data' => '', 'msg' => '文章删除成功'];
        }catch( PDOException $e){
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }


    //*********************************************风采展示*********************************************//

    /**
     * 根据搜索条件获取用户列表信息
     */
    public function getMienByWhere($map, $Nowpage, $limits)
    {
        return $this->field('think_article.*,cate_id')->where('cate_id','=',7)->page($Nowpage, $limits)->order('id desc')->select();
    }

    /**
     * [insertArticle 添加文章]
     */
    public function insertMien($param)
    {
        try{
            $result = $this->allowField(true)->save($param);
            if(false === $result){
                return ['code' => -1, 'data' => '', 'msg' => $this->getError()];
            }else{
                return ['code' => 1, 'data' => '', 'msg' => '文章添加成功'];
            }
        }catch( PDOException $e){
            return ['code' => -2, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
    /**
     * [updateArticle 编辑文章]
     */
    public function updateMien($param)
    {
        try{
            $result = $this->allowField(true)->save($param, ['id' => $param['id']]);
            if(false === $result){
                return ['code' => 0, 'data' => '', 'msg' => $this->getError()];
            }else{
                return ['code' => 1, 'data' => '', 'msg' => '文章编辑成功'];
            }
        }catch( PDOException $e){
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
    /**
     * [getOneArticle 根据文章id获取一条信息]
     */
    public function getOneMien($id)
    {
        return $this->where('id', $id)->find();
    }
    /**
     * [delArticle 删除文章]
     */
    public function delMien($id)
    {
        try{
            $this->where('id', $id)->delete();
            return ['code' => 1, 'data' => '', 'msg' => '文章删除成功'];
        }catch( PDOException $e){
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
    //*********************************************展会信息*********************************************//

    /**
     * 根据搜索条件获取用户列表信息
     */
    public function getExhibitionByWhere($map, $Nowpage, $limits)
    {
        return $this->field('think_article.*,cate_id')->where('cate_id','=',8)->page($Nowpage, $limits)->order('id desc')->select();
    }

    /**
     * [insertArticle 添加文章]
     */
    public function insertExhibition($param)
    {
        try{
            $result = $this->allowField(true)->save($param);
            if(false === $result){
                return ['code' => -1, 'data' => '', 'msg' => $this->getError()];
            }else{
                return ['code' => 1, 'data' => '', 'msg' => '文章添加成功'];
            }
        }catch( PDOException $e){
            return ['code' => -2, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
    /**
     * [updateArticle 编辑文章]
     */
    public function updateExhibition($param)
    {
        try{
            $result = $this->allowField(true)->save($param, ['id' => $param['id']]);
            if(false === $result){
                return ['code' => 0, 'data' => '', 'msg' => $this->getError()];
            }else{
                return ['code' => 1, 'data' => '', 'msg' => '文章编辑成功'];
            }
        }catch( PDOException $e){
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
    /**
     * [getOneArticle 根据文章id获取一条信息]
     */
    public function getOneExhibition($id)
    {
        return $this->where('id', $id)->find();
    }
    /**
     * [delArticle 删除文章]
     */
    public function delExhibition($id)
    {
        try{
            $this->where('id', $id)->delete();
            return ['code' => 1, 'data' => '', 'msg' => '文章删除成功'];
        }catch( PDOException $e){
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }


    //*********************************************展会信息2*********************************************//

    /**
     * 根据搜索条件获取用户列表信息
     */
    public function getInformationByWhere($map, $Nowpage, $limits)
    {
        return $this->field('think_article.*,cate_id')->where('cate_id','=',9)->page($Nowpage, $limits)->order('id desc')->select();
    }

    /**
     * [insertArticle 添加文章]
     */
    public function insertInformation($param)
    {
        try{
            $result = $this->allowField(true)->save($param);
            if(false === $result){
                return ['code' => -1, 'data' => '', 'msg' => $this->getError()];
            }else{
                return ['code' => 1, 'data' => '', 'msg' => '文章添加成功'];
            }
        }catch( PDOException $e){
            return ['code' => -2, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
    /**
     * [updateArticle 编辑文章]
     */
    public function updateInformation($param)
    {
        try{
            $result = $this->allowField(true)->save($param, ['id' => $param['id']]);
            if(false === $result){
                return ['code' => 0, 'data' => '', 'msg' => $this->getError()];
            }else{
                return ['code' => 1, 'data' => '', 'msg' => '文章编辑成功'];
            }
        }catch( PDOException $e){
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
    /**
     * [getOneArticle 根据文章id获取一条信息]
     */
    public function getOneInformation($id)
    {
        return $this->where('id', $id)->find();
    }
    /**
     * [delArticle 删除文章]
     */
    public function delInformation($id)
    {
        try{
            $this->where('id', $id)->delete();
            return ['code' => 1, 'data' => '', 'msg' => '文章删除成功'];
        }catch( PDOException $e){
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }

    //*********************************************展会信息3*********************************************//

    /**
     * 根据搜索条件获取用户列表信息
     */
    public function getTimelyByWhere($map, $Nowpage, $limits)
    {
        return $this->field('think_article.*,cate_id')->where('cate_id','=',10)->page($Nowpage, $limits)->order('id desc')->select();
    }

    /**
     * [insertArticle 添加文章]
     */
    public function insertTimely($param)
    {
        try{
            $result = $this->allowField(true)->save($param);
            if(false === $result){
                return ['code' => -1, 'data' => '', 'msg' => $this->getError()];
            }else{
                return ['code' => 1, 'data' => '', 'msg' => '文章添加成功'];
            }
        }catch( PDOException $e){
            return ['code' => -2, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
    /**
     * [updateArticle 编辑文章]
     */
    public function updateTimely($param)
    {
        try{
            $result = $this->allowField(true)->save($param, ['id' => $param['id']]);
            if(false === $result){
                return ['code' => 0, 'data' => '', 'msg' => $this->getError()];
            }else{
                return ['code' => 1, 'data' => '', 'msg' => '文章编辑成功'];
            }
        }catch( PDOException $e){
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
    /**
     * [getOneArticle 根据文章id获取一条信息]
     */
    public function getOneTimely($id)
    {
        return $this->where('id', $id)->find();
    }
    /**
     * [delArticle 删除文章]
     */
    public function delTimely($id)
    {
        try{
            $this->where('id', $id)->delete();
            return ['code' => 1, 'data' => '', 'msg' => '文章删除成功'];
        }catch( PDOException $e){
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }

    //*********************************************展会信息4*********************************************//

    /**
     * 根据搜索条件获取用户列表信息
     */
    public function getFashionByWhere($map, $Nowpage, $limits)
    {
        return $this->field('think_article.*,cate_id')->where('cate_id','=',11)->page($Nowpage, $limits)->order('id desc')->select();
    }

    /**
     * [insertArticle 添加文章]
     */
    public function insertFashion($param)
    {
        try{
            $result = $this->allowField(true)->save($param);
            if(false === $result){
                return ['code' => -1, 'data' => '', 'msg' => $this->getError()];
            }else{
                return ['code' => 1, 'data' => '', 'msg' => '文章添加成功'];
            }
        }catch( PDOException $e){
            return ['code' => -2, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
    /**
     * [updateArticle 编辑文章]
     */
    public function updateFashion($param)
    {
        try{
            $result = $this->allowField(true)->save($param, ['id' => $param['id']]);
            if(false === $result){
                return ['code' => 0, 'data' => '', 'msg' => $this->getError()];
            }else{
                return ['code' => 1, 'data' => '', 'msg' => '文章编辑成功'];
            }
        }catch( PDOException $e){
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
    /**
     * [getOneArticle 根据文章id获取一条信息]
     */
    public function getOneFashion($id)
    {
        return $this->where('id', $id)->find();
    }
    /**
     * [delArticle 删除文章]
     */
    public function delFashion($id)
    {
        try{
            $this->where('id', $id)->delete();
            return ['code' => 1, 'data' => '', 'msg' => '文章删除成功'];
        }catch( PDOException $e){
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
    //*********************************************养护技术*********************************************//

    /**
     * 根据搜索条件获取用户列表信息
     */
    public function getTechnologyByWhere($map, $Nowpage, $limits)
    {
        return $this->field('think_article.*,cate_id')->where('cate_id','=',12)->page($Nowpage, $limits)->order('id desc')->select();
    }

    /**
     * [insertArticle 添加文章]
     */
    public function insertTechnology($param)
    {
        try{
            $result = $this->allowField(true)->save($param);
            if(false === $result){
                return ['code' => -1, 'data' => '', 'msg' => $this->getError()];
            }else{
                return ['code' => 1, 'data' => '', 'msg' => '文章添加成功'];
            }
        }catch( PDOException $e){
            return ['code' => -2, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
    /**
     * [updateArticle 编辑文章]
     */
    public function updateTechnology($param)
    {
        try{
            $result = $this->allowField(true)->save($param, ['id' => $param['id']]);
            if(false === $result){
                return ['code' => 0, 'data' => '', 'msg' => $this->getError()];
            }else{
                return ['code' => 1, 'data' => '', 'msg' => '文章编辑成功'];
            }
        }catch( PDOException $e){
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
    /**
     * [getOneArticle 根据文章id获取一条信息]
     */
    public function getOneTechnology($id)
    {
        return $this->where('id', $id)->find();
    }
    /**
     * [delArticle 删除文章]
     */
    public function delTechnology($id)
    {
        try{
            $this->where('id', $id)->delete();
            return ['code' => 1, 'data' => '', 'msg' => '文章删除成功'];
        }catch( PDOException $e){
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }


    //*********************************************企业专栏*********************************************//

    /**
     * 根据搜索条件获取用户列表信息
     */
    public function getCompanyByWhere($map, $Nowpage, $limits)
    {
        return $this->field('think_article.*,cate_id')->where('cate_id','=',13)->page($Nowpage, $limits)->order('id desc')->select();
    }

    /**
     * [insertArticle 添加文章]
     */
    public function insertCompany($param)
    {
        try{
            $result = $this->allowField(true)->save($param);
            if(false === $result){
                return ['code' => -1, 'data' => '', 'msg' => $this->getError()];
            }else{
                return ['code' => 1, 'data' => '', 'msg' => '文章添加成功'];
            }
        }catch( PDOException $e){
            return ['code' => -2, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
    /**
     * [updateArticle 编辑文章]
     */
    public function updateCompany($param)
    {
        try{
            $result = $this->allowField(true)->save($param, ['id' => $param['id']]);
            if(false === $result){
                return ['code' => 0, 'data' => '', 'msg' => $this->getError()];
            }else{
                return ['code' => 1, 'data' => '', 'msg' => '文章编辑成功'];
            }
        }catch( PDOException $e){
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
    /**
     * [getOneArticle 根据文章id获取一条信息]
     */
    public function getOneCompany($id)
    {
        return $this->where('id', $id)->find();
    }
    /**
     * [delArticle 删除文章]
     */
    public function delCompany($id)
    {
        try{
            $this->where('id', $id)->delete();
            return ['code' => 1, 'data' => '', 'msg' => '文章删除成功'];
        }catch( PDOException $e){
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
}